
#pragma once


#include "muduo/net/InetAddress.h"
#include "muduo/net/TcpClient.h"

#include "muduo/base/Logging.h"
#include "muduo/net/Endian.h"

#include "muduo/base/Logging.h"
#include "muduo/net/EventLoop.h"
#include <muduo/net/EventLoopThread.h>

#include <iostream>

using namespace muduo;
using namespace muduo::net;

class ProtoClient : noncopyable {
public:
    ProtoClient(muduo::net::EventLoop *loop,
                const muduo::net::InetAddress &listenAddr);

    void connect();

    void disconnect();

    void sendMessage(string msg);

    bool getConectStatus(){
        if (connection_){
            return connection_->connected() ;
        }
        return false ;
    }

private:
    muduo::net::EventLoop *loop_;
    muduo::net::TcpClient client_;
    MutexLock mutex_;
    muduo::net::TcpConnectionPtr connection_;
    // LengthHeaderCodec codec_;


    void onConnection(const muduo::net::TcpConnectionPtr &conn);

    void onMessage(const muduo::net::TcpConnectionPtr &conn, muduo::net::Buffer *buf, muduo::Timestamp receiveTime);
};

